package Store;

public class Customer {
	private String accountID = "";
	private String customerID = "";
	private String firstName = "";
	private String lastName = "";
	private Address customerAdr;
	private String phone = "";
	private String customerAdrID = "";
	
	public Customer(String firstName, String lastName, Address customerAdr, String phone){
		this.setFirstName(firstName);
		this.setLastName(lastName);
		this.setCustomerAdr(customerAdr);
		this.setPhone(phone);
		this.setCustomerID();
	}

	public Customer(String accountID, String firstName, String lastName, Address customerAdr, String phone){
		this.setAccountID(accountID);
		this.setFirstName(firstName);
		this.setLastName(lastName);
		this.setCustomerAdr(customerAdr);
		this.setPhone(phone);
		this.setCustomerID();
	}
	
	public Customer() {
	}

	private void setCustomerID() {
		if(thereAreErrors()){
			throw new NullPointerException();
		}
		this.customerID = this.firstName+this.lastName;
	}

	private boolean thereAreErrors() {
		if(firstName == null | lastName == null || customerAdr == null || phone == null|| customerAdrID == null){
			return true;
		}
		return false;
	}

	public String getFirstName() {
		return firstName;
	}
	
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	public String getLastName() {
		return lastName;
	}
	
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	public Address getCustomerAdr() {
		return customerAdr;
	}
	
	public void setCustomerAdr(Address customerAdr) {
		this.customerAdr = customerAdr;
	}
	
	public String getPhone() {
		return phone;
	}
	
	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getCustomerAdrID() {
		return customerAdrID;
	}

	public void setCustomerAdrID(String customerAdrID) {
		this.customerAdrID = customerAdrID;
	}

	public void setAccountID(String accountID) {
		this.accountID = accountID;
	}

	public String getAccountID() {
		return accountID;
	}

	public void setCustomerID(String customerID) {
		this.customerID = customerID;
	}

	public String getCustomerID() {
		return customerID;
	}
	
	public boolean commitCustomer(){
		try{
			if(thereAreErrors()){
				throw new NullPointerException();
			}
			DatabaseAccess accessDatabase = new DatabaseAccess();
			accessDatabase.addItemToDomain(this);
		}
		catch(Exception E)
		{
			return false;
		}
		return true;
	}
	
	public static Customer[] getCustomer(String customerID){
		Customer[] temp = null;
		DatabaseAccess accessDatabase = new DatabaseAccess();
		temp = accessDatabase.getCustomer(customerID);
		return temp;
	}
}
